package com.zxy.supplier_system.server.utils.tencent.position

import org.springframework.data.domain.Pageable
import org.springframework.http.ResponseEntity

fun TencentWebPositionClient.searchSuggestion(keyword: String, region: String?, pageable: Pageable): SearchSuggestionResponse {
    val parms = mutableMapOf(
        "keyword" to keyword,
        "key" to key,
        "page_size" to pageable.pageSize.toString(),
        "page_index" to (pageable.pageNumber+1).toString(),
    )
    region?.let {
        parms["region"] = region
    }
    val api = "/ws/place/v1/suggestion"
    val result = calculateSignature(parms,api)


    // 发送请求
    val response: ResponseEntity<String> = restTemplate.getForEntity(host+result.path, String::class.java)

    // 解析JSON响应
    return objectMapper .readValue(response.body, SearchSuggestionResponse::class.java)
}

data class SearchSuggestionResponse(
    val status: Int,
    val message: String,
    val count: Int? = null,
    val data: List<PoiItem>,
){
    data class PoiItem(
        val id: String,
        val title: String,
        val address: String,
        val tel: String?,
        val category: String,
        val type: Int,
        val location: Location,
        val adcode: String,
        val province: String,
        val city: String,
        val district: String
    )

    data class Location(
        val lat: Double,
        val lng: Double
    )


}